const app = getApp()
let host = app.globalData.host;
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
  },
 
  //表单提交
  formSubmit(e){

    let {goodsType,goodsName,goodsImg,goodsPrice,goodsCutPrice,goodsUnit} = e.detail.value
    wx.request({
      url: host+'/addGoods',
      data: {
        goodsType: goodsType,
        goodsName: goodsName,
        goodsImg: goodsImg,
        goodsPrice: goodsPrice,
        goodsCutPrice: goodsCutPrice,
        goodsUnit: goodsUnit
      },
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },success (res) {
      console.log(res.data)
      },
      fail (error){
        console.log("失败") 
      }
    })
    wx.redirectTo({
      url: '../menu/menu'
    })

  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  unploadImg(e) {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        that.setData({
            'uploadImg': res.tempFilePaths
        })

        wx.uploadFile({
          url: host+"/uploadImg",
          filePath: res.tempFilePaths[0],
          name: 'file',
          success: (res) =>{
            let uploadImg = res.data
            console.log(uploadImg)
            that.setData({
              goodsImg: uploadImg
            })
           },
           fail(err) {
             console.log(err)
          }
         })
      },
      fail(error) {
        console.log(error)
      }
      })
  },

  onLoad: function (options) {

    this.setData({
      goodsType: options.goodsType
    })
  }
})

